package com.ocl.www.utils;

/**
 * Created by Administrator on 2016/11/2.
 */
import com.qiniu.api.auth.AuthException;
import org.json.JSONException;
import sun.misc.BASE64Encoder;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;


/**
 * Created by shadow on 2015/11/29.
 */
public class QiniuTest {

    private QiniuUntil qiniuService = null;

    public void init() {
        qiniuService = new QiniuUntil();
        //设置AccessKey
        qiniuService.setAccessKey("3Z8mQL2tyrFUt7EsebbSAX7G5zwjTf_HvTRs-VDe");
        //设置SecretKey
        qiniuService.setSecretKey("9aQrKE6rpgaSj1HGn_2gZ4fbfptnf_KyQBcHIpJj");
        //设置存储空间
        qiniuService.setBucketName("ocl-server");
        //设置七牛域名
        qiniuService.setDomain("og0364yqk.bkt.clouddn.com");
    }

    public void testUpload() throws AuthException, JSONException {
        File file = new File("E:/shadow1.jpg");
        file.toString();
        qiniuService.uploadFile(file);
    }

    public void testDownloadFileUrl() throws Exception {
        String filePath = qiniuService.getDownloadFileUrl("shadow.jpg");
        System.out.println("file path == " + filePath);
    }

    public void uploadFile() throws Exception {

        File f = new File("E:/shadow.jpg");
        InputStream is = new FileInputStream(f);

        String key = "callbell.jpg";
        qiniuService.uploadFile(key,is);

    }

    public static void main(String[] args){

        QiniuTest qt = new QiniuTest();
        qt.init();

        try {
//          qt.testUpload();
            qt.uploadFile();

        } catch (AuthException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
